
package com.yyfax.ph.personal.settings;

import android.os.Parcel;
import android.os.Parcelable;
import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.ph.base.YJPH;

import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

public class BankCardModel extends Model {
	private static final String TAG = BankCardModel.class.getSimpleName();

	public static final int MSG_GET_BANK_CARD=101;

	@Override
	public void onNext(Object obj) {
		CLog.i(TAG, "onNext: " + obj.toString());
		BankCardResult bankCardResult = cast(obj);
		EventAgent.post(bankCardResult);
	}

	@Override
	public Observable getObservable(Object params, int functionalCode) {
		Service service = (Service) NetworkHelper.createService(Service.class);
		String token = YJPH.getInstance().getPreferenceManager().getLoginToken();
		return service.getBankCardInfo(token, new BankCard());
	}

	public interface Service {
		@POST("account/card/info")
		Observable<BankCardResult> getBankCardInfo(@Header("token") String token, @Body BankCard params);
	}

	public static class BankCard {

	}

	public static class BankCardResult extends BaseResultEntity<Content> {

	}

	public static class Content {
		CardInfo cardInfo;//银行卡信息
		String bindStatus;//绑定状态 0:未实名认证，1:未绑定银行卡，2:已绑定银行卡

		public static class CardInfo implements Parcelable {
			public String id;//暂时用不到这个字段
			public String name;//姓名
			public String certId;//身份证号
			public String cardId;//银行卡号
			public String bank;//银行名称
			public String bankCode; //银行code


			public CardInfo() {
			}

			@Override
			public int describeContents() {
				return 0;
			}

			@Override
			public void writeToParcel(Parcel dest, int flags) {
				dest.writeString(this.id);
				dest.writeString(this.name);
				dest.writeString(this.certId);
				dest.writeString(this.cardId);
				dest.writeString(this.bank);
				dest.writeString(this.bankCode);
			}

			protected CardInfo(Parcel in) {
				this.id = in.readString();
				this.name = in.readString();
				this.certId = in.readString();
				this.cardId = in.readString();
				this.bank = in.readString();
				this.bankCode = in.readString();
			}

			public static final Creator<CardInfo> CREATOR = new Creator<CardInfo>() {
				@Override
				public CardInfo createFromParcel(Parcel source) {
					return new CardInfo(source);
				}

				@Override
				public CardInfo[] newArray(int size) {
					return new CardInfo[size];
				}
			};
		}

		@Override
		public String toString() {
			return "Content{" +
					"cardInfo=" + cardInfo +
					", bindStatus='" + bindStatus + '\'' +
					'}';
		}
	}

}
